import java.util.LinkedList;


public class Blast extends EnergyAttack{

	private float direction;
	private float damage;
	private float speed;
	private boolean life;
	private Sprite sprite;
	private int characterNumber;
	private final int MAX_LENGTH = 400;
	/**
	 * creates a new attack wave
	 * @param source the starting point of the wave
	 * @param direction the direction the wave will advance in
	 * @param damage the amount of damage the wave does.
	 */
	public Blast(Sprite sprite,Point source, float direction,float damage, int characterNumber)
	{
		life = true;
		this.radius = 10;
		this.speed = 20;
		this.currentPosition = source;
		currentPosition.setX(currentPosition.getX() - (float)(Math.cos(direction)*speed));
		currentPosition.setY(currentPosition.getY() - (float)(Math.sin(direction)*speed));
		this.direction = direction;
		this.damage = damage;
		this.sprite = sprite;
		this.characterNumber = characterNumber;
	}
	/**
	 * overwrites the collision detection for normal objects
	 */
	public boolean checkCollision(Collidable collidable)
	{
		return false;
	}
	
	public boolean isAlive()
	{
		return life;
	}
	public int getCurrentImage()
	{
		return sprite.getImg();
	}
	public float getAngle()
	{
		return direction;
	}
	public int getType()
	{
		return sprite.getType();
	}
	/**
	 * on a collision, the blast should destroy itself
	 */
	public void onCollision(Collidable c)
	{
		c.damage(damage);
		life = false;
	}
	/**
	 * sets the speed of the wave
	 * @param speed
	 */
	public void setSpeed(float speed)
	{
		this.speed = speed;
	}
	public void setRadius(float radius)
	{
		this.radius = radius;
	}
	/**
	 * tells the wave that it is still being produced
	 */
	public void add()
	{
		currentPosition.setX(currentPosition.getX() + (float)(Math.cos(direction)*speed));
		currentPosition.setY(currentPosition.getY() + (float)(Math.sin(direction)*speed));
	}
	
	public String getDrawableString()
	{
		String ans = "";
		int x = (int)(currentPosition.getX());
		String temp0 =  x +"";
		temp0 = paddZeros(temp0,7);
		int y = (int)(currentPosition.getY());
		String temp1 = y +"";
		temp1 = paddZeros(temp1,7);
		String temp2 = ((int)Math.toDegrees((getAngle()))) + "";
		temp2 = paddZeros(temp2,7);
		String temp3 = characterNumber + "";
		temp3 = paddZeros(temp3,2);
		String temp4 = sprite.getType() + "";
		temp4 = paddZeros(temp4,2);
		String temp5 = sprite.getImg() + "";
		temp5 = paddZeros(temp5,1);
		ans = "Blast: " + temp0 + temp1 + temp2 + temp3 + temp4 + temp5 + "\n";
		return ans;
	}
	public String paddZeros(String str,int gg)
	{
		String a = str + "";
		if(a.length() > gg)
		{
			str = str.substring(0,gg);
		}
		while(a.length() < gg)
		{
			if(str.charAt(0) == '-')
			{
				String temp = "-0" + a.substring(1);
				a = temp;
			}
			else
			{
				a = "0" + a;
			}
		}
		return a;
	}
	@Override
	public void done() {
		// TODO Auto-generated method stub
		
	}
}
